package com.rssfeed.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DBSqliteHelper extends SQLiteOpenHelper{

	private static final String DB_NAME = "VOARssFeed.db";
	private static final int DB_VERSION = 1;
	
	public static final String TABLE_DATA = "VOA";
	public static final String mFeedId = "feedId";
	public static final String mTitle = "title";
	public static final String mDescription = "description"; 
	public static final String mLink = "link";
	public static final String mImageLink = "imageLink";
	public static final String mPubDate = "pubDate";
	public static final String mMp3Link = "mp3Link";
	
	private static final String DATABASE_CREATE = "create table "
			+ TABLE_DATA + "(" 
			+ mFeedId + " text not null primary key, " 
			+ mTitle + " text not null, " 
			+ mLink+ " text, "
			+ mDescription + " text, " 	
			+ mPubDate + " text, "
			+ mImageLink+ " text, "
			+ mMp3Link + " text );";
	
	public DBSqliteHelper(Context context) {
		// create database
		super(context, DB_NAME, null, DB_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		db.execSQL(DATABASE_CREATE);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		Log.w(DBSqliteHelper.class.getName(),
				"Upgrading database from version " + oldVersion + " to "
						+ newVersion + ", which will destroy all old data");
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_DATA);
		onCreate(db);
	}
	
}
